package com.yjhb.android.sbz.tool;


/**
 * @author zx
 * 2020/12/29 20:49
 *
 * 计算扇形外的中心落脚点
 **/

public class FanShapeMathTool {

    /**
     * @param radius   圆半径
     * @param x        圆x点 （圆中心点）
     * @param y        圆y点 （圆中心点）
     * @param spacing  文字与圆的间距
     * @param arcAngle 扇形角度  如45°
     * @param offAngle 偏移角度
     * @return  得到扇形外的中心点。
     */
    public static Point CalculatePoint(double radius, double x, double y, double spacing, double arcAngle, double offAngle) {
        Point point = CalculateOff(x,y, radius, spacing,arcAngle, offAngle);
        System.out.println(point);
        return point;
    }


    /**
     * 通过偏差，计算得到正确的值
     *
     * @param offAngle
     * @return
     */
    private static Point CalculateOff(double x, double y, double radius, double spacing, double arcAngle, double offAngle) {
        Point target = new Point();
        double radian = Math.toRadians(offAngle+(arcAngle/2));
        double offX = (radius+spacing) * Math.cos(radian);
        double offY = (radius+spacing) * Math.sin(radian);
        target.x = offX+x;
        target.y = offY+y;
        return target;
    }


    private static Point CenterPoint(double radius, double arcAngle) {
        Point target = new Point();
        target.x = radius  ;
        target.y = K(arcAngle) * radius;
        return target;
    }

    /**
     * 斜率
     *
     * @return
     */
    private static double K(double arcAngle) {
        return Math.tan(Math.toRadians(arcAngle / 2));
    }


    public static class Point {
        double x, y;

        public Point(double x, double y) {
            this.x = x;
            this.y = y;
        }

        public Point() {

        }

        public double getX() {
            return x;
        }

        public void setX(double x) {
            this.x = x;
        }

        public double getY() {
            return y;
        }

        public void setY(double y) {
            this.y = y;
        }

        @Override
        public String toString() {
            return "Point{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }
    }
}
